//
//  NoticeDetailViewController.m
//  wtshoppingcite
//
//  Created by TW on 15-1-13.
//  Copyright (c) 2015年 TW. All rights reserved.
//

#import "NoticeDetailViewController.h"
#import "AdviseDetailModel.h"

@interface NoticeDetailViewController ()<UIWebViewDelegate>
{
    UITableView *detailTableView;
    NSString *pageNum;

}
@property(nonatomic,strong)AdviseDetailModel *adviseDetailModel;
@property(nonatomic,strong)UIWebView *webView;
@property(nonatomic,strong)UIActivityIndicatorView *activityIndicator;

@end

@implementation NoticeDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self getCommunityDetailList:NO];
    
    [self setTitleView:@"通知详情"];
    // Do any additional setup after loading the view.
}

#pragma mark getNearkgrouplist 三公里商圈
-(void)getCommunityDetailList:(BOOL)isMore{
    
    NSMutableDictionary *listDic = [NSMutableDictionary dictionary];
    SetValueForKey(listDic, self.communityId, @"adviseId");
    
    [self showLoadImageView:self.view subview:detailTableView];
    [NetWorkService byRequestWithAPIPrefix:kBaseAppUrl
                              andAPISuffix:kDetailAdvise
                             andHttpMethod:@"POST"
                             andParameters:listDic
                           andRequestCache:NO
                            andUseParamDic:YES
                       andPostDataEncoding:MKNKPostDataEncodingTypeJSON
                     andRequestFinishBlock:^(BYRequest *request, BYResponse *response) {
                         
                         [self performSelector:@selector(dismissLoadImageView) withObject:nil afterDelay:0.5];
                         
                         request.requestCache = YES;
                         
                         if (response.isError) {
                             
                             DLog(@"error %@",response.errorMessage);
                             
                         }else{
                             
                             NSDictionary *responseDic = request.responseJSON;
                             DLog(@"成功数据:%@",responseDic);
                             
                             id dic = [responseDic objectForKey:@"advise"];
                             
                             AdviseDetailModel *shoppingModel = [[AdviseDetailModel alloc]initWithCommunityDetailList:dic];
                             self.adviseDetailModel = shoppingModel;
                             
                         }
                         //[detailTableView reloadData];
                         [self initWithView];
                     }];
}

-(void)initWithView{
    
    UILabel *titleLabel = [self createLabelWithFrame:CGRectMake(10, 5, 220, 20) text:@"" font:16 textAli:NSTextAlignmentLeft textColor:MAIN_BLACK_COLOR];
    titleLabel.tag = 100;
    [self.view addSubview:titleLabel];
    
    titleLabel.text = self.adviseDetailModel.title;
    
    
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(10, titleLabel.bottom, kWidth-20, kHeight - 84)];
    _webView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_webView];
    //_webView.scalesPageToFit = YES;
    
 
    [_webView setUserInteractionEnabled:YES];  //是否支持交互
    [_webView setDelegate: self];     //委托
    
    NSString* content = self.adviseDetailModel.content;
    NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
    [_webView loadHTMLString:content baseURL:baseURL];
    
    
    _activityIndicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(10,10,20,20)];//需要在.h文件中进行声明
    
    [_activityIndicator setCenter:_webView.center];//位置
    
    [_activityIndicator   setActivityIndicatorViewStyle: UIActivityIndicatorViewStyleGray];//颜色根据不同的界面自己调整
    
    [self.view  addSubview:_activityIndicator];
}



#pragma mark - webview
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    
    float htmlHeight = [[_webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
    [(UIScrollView *)[[_webView subviews] objectAtIndex:0] setContentSize:CGSizeMake(300, htmlHeight)];
    
    _webView.hidden = NO;
    [_activityIndicator stopAnimating];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    
    [_activityIndicator stopAnimating];
    //    [self showHUDWithString:@"网络错误！"];
    
    NSLog(@"error :%@",error);
    
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [_activityIndicator startAnimating];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self getCommunityDetailList:NO];
    ;
}


- (void)viewWillDisappear:(BOOL)animated
{
    
    [super viewWillDisappear:animated];
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
